<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>豆瓣</title>
    <script src="lib/jquery-3.4.1.js"></script>
    <script src="lib/http.js"></script>
    <style>
        body{
            padding-left: 380px;
            padding-right: 340px;
            padding-top: 30px;
        }
        div{
            width: 170px;
            height: 260px;
            border: 1px solid rgb(223, 222, 222);
            box-shadow: 1px 1px 7px 2px rgb(175, 175, 175);
            float: left;
            margin-bottom: 20px;
            margin-right: 20px;
              
        }
       img{
           width: 150px;
           height: 225px;
           margin-top: 10px;
           margin-left: 10px;
       }
       p{
           margin: 0 10px;
       }
    </style>
</head>
<body>
    <script>
        var start = 0;
        http({
            data: {
                start
            },
            callback: handleData
        })

        function handleData(res) {
            var subjects = res.subjects;
            var movies = [];
            for (var i = 0; i < subjects.length; i++) {
                var obj = {}
                obj.title = subjects[i].title;
                obj.imageUrl = subjects[i].images.small;
                movies.push(obj)
            }

            for (var j = 0; j < movies.length; j++) {
                var item = $(`<div class="item"><img src="${movies[j].imageUrl}"/><p>${movies[j].title}</p></div>`)
                $("body").append(item)
            }

            $(window).scroll(function(){
                if(onReachBottom()){
                    start+=20;
                    http({
                        data:{
                            start
                        },
                        callback:handleData
                    })
                }
            })
        }
    </script>
</body>
</html>